<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" import="java.util.*" isELIgnored="false"
	import="com.jeremy.entity.*"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt_rt"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>用户管理系统</title>
	<link href="static/css/bootstrap.min.css" rel="stylesheet">
	<script src="static/js/jquery-3.4.0.min.js"></script>
	<script src="static/js/bootstrap.min.js"></script>
	<script type="text/javascript">
		$(function(){
			$("#add").click(function(){
				window.location.href = "<%=path%>/addPage";
			});
		});
	</script>
</head>
<body>

	<!--通过bootstrap的栅格系统布局-->
	<div class="container">
		<!--标题-->
		<div class="row">
			<div class="col-md-12">
				<h1>SSM-CRUD-列表</h1>
				<h1>path:<%=path %></h1>
				<h1>basePath:<%=basePath %></h1>
			</div>
		</div>
		<div class="row">
			<div class="col-md-12">
				<button type="button" id="add" class="btn btn-primary">新增</button>
			</div>
		</div>
		<!--显示表格数据-->
		<div class="row">
			<div class="col-md-12">
				<table class="table table-bordered">
					<thead>
						<tr>
							<td>ID</td>
							<td>姓名</td>
							<td>性别</td>
							<td>年龄</td>
							<td>出生日期</td>
							<td>操作1</td>
							<td>操作2</td>
						</tr>
					</thead>
					<tbody>
						<c:forEach items="${pageInfo.list}" var="user" varStatus="index">
							<tr>
								<td>${user.id}</td>
								<td>${user.name}</td>
								<td>${user.sex}</td>
								<td>${user.age}</td>
								<td><fmt:formatDate value="${user.birthdate}" pattern="yyyy-MM-dd"></fmt:formatDate></td>
								<td><a class="btn btn-primary"
									href="<%=path %>/editUser?id=${user.id}"> <span
										class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
										修改
								</a></td>	
								<td><a class="btn btn-primary"
									href="<%=path %>/deleteUser?id=${user.id}"> <span
										class="glyphicon glyphicon-trash" aria-hidden="true"></span>
										删除
								</a></td>
							</tr>
						</c:forEach>
					</tbody>
				</table>
				<!--
				<div style="text-align:center">
					<p>当前页：第 ${pageInfo.pageNum }页,总页数：${pageInfo.pages }页,共
						${pageInfo.total } 条记录</p>
					<a href="index?pageNo=1">第一页</a>
					<c:if test="${pageInfo.hasPreviousPage }">
						<a href="index?pageNo=${pageInfo.pageNum-1}">上一页</a>
					</c:if>
					<c:if test="${pageInfo.hasNextPage }">
						<a href="index?pageNo=${pageInfo.pageNum+1}">下一页</a>
					</c:if>
					<a href="index?pageNo=${pageInfo.pages}">最后页</a>
				</div>
				<div style="text-align:center;margin-top:40px">
					<form method="post" action="addCategory">
						分类名称： <input name="name" value="" type="text"> <br>
						<br> <input type="submit" value="增加分类">
					</form>
				</div>
				-->
			</div>
		</div>
		<!-- table end -->
		
		<!--显示分页信息-->
		<div class="row">
			<!--文字信息-->
			<div class="col-md-6">当前第 ${pageInfo.pageNum} 页.总共
				${pageInfo.pages} 页.一共 ${pageInfo.total} 条记录</div>

			<!--点击分页-->
			<div class="col-md-6">
				<nav aria-label="Page navigation">
					<ul class="pagination">

						<li><a href="${pageContext.request.contextPath}/index?pageNo=1">首页</a></li>

						<!--上一页-->
						<li><c:if test="${pageInfo.hasPreviousPage}">
								<a
									href="${pageContext.request.contextPath}/index?pageNo=${pageInfo.pageNum-1}"
									aria-label="Previous"> <span aria-hidden="true">«</span>
								</a>
							</c:if></li>

						<!--循环遍历连续显示的页面，若是当前页就高亮显示，并且没有链接-->
						<c:forEach items="${pageInfo.navigatepageNums}" var="page_num">
							<c:if test="${page_num == pageInfo.pageNum}">
								<li class="active"><a href="#">${page_num}</a></li>
							</c:if>
							<c:if test="${page_num != pageInfo.pageNum}">
								<li><a
									href="${pageContext.request.contextPath}/index?pageNo=${page_num}">${page_num}</a></li>
							</c:if>
						</c:forEach>

						<!--下一页-->
						<li><c:if test="${pageInfo.hasNextPage}">
								<a
									href="${pageContext.request.contextPath}/index?pageNo=${pageInfo.pageNum+1}"
									aria-label="Next"> <span aria-hidden="true">»</span>
								</a>
							</c:if></li>

						<li><a
							href="${pageContext.request.contextPath}/index?pageNo=${pageInfo.pages}">尾页</a></li>
					</ul>
				</nav>
			</div>

		</div>


	</div>
</body>
</html>
